﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace HQPad.Models
{
    /// <summary>
    /// The SkillView duplicates the Skill entity object but differs in two repects.
    /// Firstly it is not a tracked entity.  Secondly, it adds the 'Allowed' bool property
    /// which indicates whether the skill has fulfilled all it's requirements.  If it is false
    /// the the skill is allowed by the guild (and level) of a character
    /// </summary>
    public class SkillView
    {
        public SkillView() { }

        public SkillView(Skill skill, bool allowed)
        {
            SkillID = skill.SkillID;
            RuleSetID = skill.RuleSetID;
            LegacyName = skill.LegacyName;
            Slug = skill.Slug;
            Deleted = skill.Deleted;
            LastUpdated = skill.LastUpdated;
            LastUpdatedByUserID = skill.LastUpdatedByUserID;
            MaxRanks = skill.MaxRanks;
            IsBasic = skill.IsBasic;
            Status = skill.Status;
            TypeOfSkill = skill.TypeOfSkill;
            Description = skill.Description;
            Allowed = allowed;
        }

        public int SkillID { get; set; }

        [ForeignKey("Rules")]
        public int RuleSetID { get; set; }
        public virtual RuleSet Rules { get; set; }

        [Display(Name = "Skill name")]
        [Required(ErrorMessage = "A skill name is required")]
        [MaxLength(50, ErrorMessage = "The skill name is limited to 50 characters")]
        public string Name { get; set; }

        [Display(Name = "Legacy skill name")]
        [MaxLength(50, ErrorMessage = "The legacy skill name is limited to 50 characters")]
        public string LegacyName { get; set; }

        [Display(Name = "Unique skill slug")]
        [Required(ErrorMessage = "A skill slug is required")]
        [MaxLength(50, ErrorMessage = "The skill slug is limited to 50 characters")]
        public string Slug { get; set; }

        public bool Deleted { get; set; }

        [Display(Name = "Last updated")]
        [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
        public DateTime? LastUpdated { get; set; }

        [Display(Name = "Last updated by")]
        public int? LastUpdatedByUserID { get; set; }

        [Display(Name = "Max ranks")]
        public int? MaxRanks { get; set; }

        [Required(ErrorMessage = "The basic skill flag is required")]
        [Display(Name = "Is a basic skill")]
        public bool IsBasic { get; set; }

        [Display(Name = "Skill status cost per rank.")]
        public int? Status { get; set; }

        [Display(Name = "Skill Group")]
        [Required(ErrorMessage = "A skill group is required")]
        [MaxLength(20, ErrorMessage = "The type of skill is limited to 20 characters")]
        [RegularExpression("Martial|Archer|Physical|Medical|Magic|Power|Subterfuge|Armour|Potion|Ki|Adrenal|Psi|Royal|Other|Special128|Special256")]
        public string TypeOfSkill { get; set; }

        [Display(Name = "Skill description")]
        public string Description { get; set; }

        /// <summary>
        /// Whether the skill has fulfilled all it's requirements for a character.
        /// </summary>
        public bool Allowed { get; set; }
    }
}